<template>
  <div class="app-container">

    <MmvTitle title="预付费"></MmvTitle>
    <el-table :data="detail.chargingItems" border style="width: 100%; margin-top: 20px">
      <el-table-column _min-width="200" label="费用名称" align="center" prop="name" />
      <el-table-column _min-width="200" label="收费金额" align="center" prop="chargeMoney" />
      <el-table-column _min-width="160" label="支付方式" align="center" prop="methodPayment"/>
      <el-table-column _min-width="160" label="支付状态" align="center" prop="payStatusStr"/>
    </el-table>
<!--    <br>
    <MmvTitle title="退款凭证"></MmvTitle>
    <el-form label-width="100">
      <el-row :gutter="15">
        <el-col :span="24">
          <el-form-item label="支付凭证">
            <ImageUpload v-model="url" :limit="1" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>-->
    <div slot="footer" class="dialog-footer" style="text-align: end;">
      <el-button @click="closeDiolog">取消</el-button>
      <el-button type="primary" :loading="submitBtnLoading" @click="submitData">确定</el-button>
    </div>
  </div>
</template>

<script>
import {
  costDetail,
  cancel
} from '@/api/longOrder/index';
  import MmvTitle from '@/components/MmvUI/MmvTitle.vue';
  import * as api from "@/api/order/voucher";
  export default {
    components: {
      MmvTitle,
    },
    dicts: ['sys_pay_type', 'order_payStatus', 'charge_type','refund_type'],
    props: ['orderNo'],
    data() {
      return {
        nowId: null,
        detail: {
        },
        loading: true,
        btnLoadIng: false,
        url: "", // 支付凭证
        submitBtnLoading:false
      }
    },
    mounted() {
      this.costDetail();
    },
    methods: {
      closeDiolog() {
        this.$emit('close');
      },
      costDetail() {
        costDetail(this.orderNo).then(response => {
          this.detail = response.data || {};
          this.loading = false
        });
      },
      submitData() {
        this.submitBtnLoading=true
        cancel(this.orderNo,1).then(response => {
          this.submitBtnLoading=false
          this.$message.success(response.msg);
          this.closeDiolog();
        });
      },
      getSummaries(param) {
        const {
          columns,
          data
        } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
          if (index === 1) {
            const values = data.map(item => Number(item[column.property]));
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += ' 元';
          }
        });

        return sums;
      },
      objectSpanMethod({
                         row,
                         column,
                         rowIndex,
                         columnIndex
                       }) {
        let rowspan = this.detail.chargingItems.length - 2;
        if (columnIndex === 0 || columnIndex > 5) {
          if (rowIndex === 0 && rowIndex < rowspan) {
            return {
              rowspan: rowspan,
              colspan: 1
            };
          } else if (rowIndex > 0 && rowIndex < rowspan) {
            return {
              rowspan: 0,
              colspan: 0
            };
          }
        }

        if (columnIndex > 5 && rowIndex >= rowspan) {
          if (rowIndex === rowspan) {
            return {
              rowspan: 2,
              colspan: 1
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0
            };
          }
        }
        if (rowIndex >= rowspan) {
          if (columnIndex === 0) {
            return [1, 2];
          } else if (columnIndex === 1) {
            return [0, 0];
          } else if (columnIndex === 5) {
            return [1, 4];
          } else if (columnIndex < 5) {
            return [0, 0];
          }
        }
      }

    },

  }
</script>
